from flask import session, jsonify, Blueprint, request

is_login_service = Blueprint('is_login_service', __name__)


# 自定义中间件，用于验证会话
@is_login_service.before_request
def session_checker():
    # 排除登录和注册接口，其他接口都需要验证会话
    if request.endpoint not in ['auth.login', 'auth.register']:
        if 'user' not in session:
            return jsonify(error='Unauthorized'), 401
